package com.ruoyi.framework.web.service;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.service.IShopUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.system.domain.ShopUser;

@Component
public class WebLoginService {
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IShopUserService shopUserService;

    public ShopUser validateCaptcha(String username, String password, String code, String uuid)
    {
            //验证密码
           ShopUser userInfo = shopUserService.selectShopUserByUserName(username);
           if(userInfo ==null){
               throw new ServiceException("用户不存在");
           }
           if(!userInfo.getPassword().equals(password)){
               throw new ServiceException("密码不正确");
           }

           //判断用户是企业用户还是个人用户
//           if(userInfo.getUserType().equals("1")){
//               //企业用户
//               if(userInfo.getShopCompanyInfoList().size()==0){
//                   throw new ServiceException("请先完善企业信息");
//               }
//           }
           /* String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
            String captcha = redisCache.getCacheObject(verifyKey);
            redisCache.deleteObject(verifyKey);
            if (captcha == null)
            {
                throw new ServiceException("验证码为空");
            }
            if (!code.equalsIgnoreCase(captcha))
            {
                throw new ServiceException("验证码不正确");
            }*/

            return  userInfo;
    }

}
